package com.example.hasee.zhcd.Activities.ChuanWu;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hasee.zhcd.Activities.ShangWu.AtPortDetailActivity;
import com.example.hasee.zhcd.Base.BaseActivity;
import com.example.hasee.zhcd.Bean.EventMsg;
import com.example.hasee.zhcd.R;
import com.example.hasee.zhcd.Util.ProgressDialogUtils;

import org.json.JSONObject;

import java.util.HashMap;

import static com.example.hasee.zhcd.R.id.fberth;
import static com.example.hasee.zhcd.R.id.fhc;
import static com.example.hasee.zhcd.R.id.fhl;
import static com.example.hasee.zhcd.R.id.fht;
import static com.example.hasee.zhcd.R.id.fkbsj;
import static com.example.hasee.zhcd.R.id.fkgsj;
import static com.example.hasee.zhcd.R.id.flgsj;
import static com.example.hasee.zhcd.R.id.flx;
import static com.example.hasee.zhcd.R.id.fpzton;
import static com.example.hasee.zhcd.R.id.fwgsj;
import static com.example.hasee.zhcd.R.id.fwtf;
import static com.example.hasee.zhcd.R.id.fwxp;
import static com.example.hasee.zhcd.R.id.fyb;
import static com.example.hasee.zhcd.R.id.fybton;

/**
 * Created by hasee on 2018/6/13.
 */

public class ShipDetailActivity extends BaseActivity {
    private TextView title;
    private ImageView back;
    private ImageView home;
    private String strSYN;
    private TextView fshipname;
    private TextView fhuhao;
    private TextView fshiptype;
    private TextView fphone;
    private TextView flength;
    private TextView fwidth;
    private TextView fmaxweigh;
    private TextView fjd;
    private TextView fzd;
    private TextView fcabin;
    private TextView fdraintime;
    private TextView fcbsbh;

    @Override
    public int contentViewId() {
        return R.layout.activity_ship_detail;
    }

    @Override
    public void set() {
        title.setText("船舶规范");
        back.setOnClickListener(this);
        home.setVisibility(View.INVISIBLE);
        getDetail();
    }

    @Override
    public void init() {
        strSYN = getIntent().getExtras().getString("strSYN");
        title = (TextView) findViewById(R.id.centertitle);
        back = (ImageView) findViewById(R.id.back);
        home = (ImageView) findViewById(R.id.home);
        fshipname = (TextView) findViewById(R.id.fshipname);
        fhuhao = (TextView) findViewById(R.id.fhuhao);
        fshiptype = (TextView) findViewById(R.id.fshiptype);
        fphone = (TextView) findViewById(R.id.fphone);
        flength = (TextView) findViewById(R.id.flength);
        fwidth = (TextView) findViewById(R.id.fwidth);
        fmaxweigh = (TextView) findViewById(R.id.fmaxweigh);
        fjd = (TextView) findViewById(R.id.fjd);
        fzd = (TextView) findViewById(R.id.fzd);
        fcabin = (TextView) findViewById(R.id.fcabin);
        fdraintime = (TextView) findViewById(R.id.fdraintime);
        fcbsbh = (TextView) findViewById(R.id.fcbsbh);

    }

    private void getDetail() {
        ProgressDialogUtils.createProgressDialog(ShipDetailActivity.this, "正在获取数据...");
        HashMap<String, String> map = new HashMap<String, String>();
        Log.e("strSYN", strSYN);
        map.put("strSYN", strSYN);
        httpUtils.get("ZHCW_ShipDetail", map, "ZHCW_ShipDetail");
    }

    @Override
    public void getEventData(EventMsg msg) {
        switch (msg.getAction()) {
            case "Fail":
                ProgressDialogUtils.closeProgressDialog();
                Toast.makeText(ShipDetailActivity.this, "操作失败，请检查网络！", Toast.LENGTH_LONG).show();
                break;
            case "ZHCW_ShipDetail":
                ProgressDialogUtils.closeProgressDialog();
                Log.e("ZHCW_ShipDetail", msg.getMsg());
                try {
                    JSONObject json = new JSONObject(msg.getMsg());
                    String rspcode = json.getString("rspcode");
                    String rspmessage = json.getString("rspmessage");
                    if ("0".equals(rspcode)) {
                        JSONObject data = json.getJSONArray("data").getJSONObject(0);
                        fshipname.setText(data.getString("fshipname"));
                        fhuhao.setText(data.getString("fhuhao"));
                        fshiptype.setText(data.getString("fshiptype"));
                        fphone.setText(data.getString("fphone"));
                        flength.setText(data.getString("flength"));
                        fwidth.setText(data.getString("fwidth"));
                        fmaxweigh.setText(data.getString("fmaxweigh"));
                        fjd.setText(data.getString("fjd"));
                        fzd.setText(data.getString("fzd"));
                        fcabin.setText(data.getString("fcabin"));
                        fdraintime.setText(data.getString("fdraintime"));
                        fcbsbh.setText(data.getString("fcbsbh"));
                    } else {
                        Toast.makeText(ShipDetailActivity.this, rspmessage, Toast.LENGTH_LONG).show();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
        }
    }
}
